<template>
  <div class="login">
    <el-card>
      <!-- <h1>登录</h1> -->
      <el-form ref="form" :model="form" label-width="80px">
        <el-form-item label="用户名">
          <el-input v-model="form.name"></el-input>
        </el-form-item>
        <el-form-item label="密码">
          <el-input
            placeholder="请输入密码"
            v-model="form.password"
            show-password
          ></el-input>
        </el-form-item>
        <el-button
          type="primary"
          icon="el-icon-right"
          circle
          size="medium"
          @click="login(form)"
        ></el-button>
      </el-form>
    </el-card>

    <!-- 确认对话框区域 -->
    <el-dialog
      title="为了确认是本人操作 请验证"
      :visible.sync="dialogVisible"
      width="350px"
    >
      <slide-verify
        :l="42"
        :r="10"
        :w="310"
        :h="155"
        slider-text="向右滑动"
        @success="onSuccess"
        @fail="onFail"
        @refresh="onRefresh"
      ></slide-verify>
      <div>{{ msg }}</div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      // 用户信息
      form: {
        name:"admin",
        password:"123456"
      },
      // 验证返回的值
      msg: "",
      // 控制对话框展示 隐藏
      dialogVisible: false,
    };
  },
  methods: {
    login(e) {
      if (e.name == "admin" && e.password == "123456") {
        this.dialogVisible = true
      } else {
        this.$message.error("登陆失败");
      }
    },
    onSuccess(e) {
      let str = (e / 1000).toFixed(1);
      window.localStorage.setItem("usr",this.form.name);
      this.msg = `太棒了 只用了 ${str} 秒！`
      this.$router.push("/list");
      this.$message.success("登陆成功");
      // console.log(localStorage.getItem("usr"))
    },
    onFail() {
      this.msg = "验证失败";
    },
    onRefresh() {
      this.msg = "";
    },
  },
};
</script>
<style lang="less" scoped>
.login {
  width: 100%;
  height: 100vh;
  background-color: #ecf5ff;
  .el-card {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    // flex-direction:row-reverse;
    width: 380px;
    height: 400px;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
    margin: auto;
    .el-button {
      width: 80px;
      height: 80px;
      font-size: 50px;
      background-color: #409eff;
      border: none;
      margin-left: 130px;
      margin-top: 30px;
    }
  }
}
</style>